<template>
<el-dialog title="就业登记" :visible.sync="dialogVisible" width="800px">
  <el-form ref="jobRegisterForm" label-width="80px" :rules="rules" :model="jobRegisterForm">
    <el-row :gutter="24">
      <el-col :span="12">
        <el-form-item label="就业类型" prop="djlx00">
          <el-select v-model="jobRegisterForm.djlx00" placeholder="请选择" clearable style="width: 100%">
            <el-option v-for="item in djlx00Options" :key="item.dictValue" :value="item.dictValue" :label="item.remark"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="登记时间" prop="djrq00">
          <el-date-picker
            style="width: 100%"
            v-model="jobRegisterForm.djrq00"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择">
          </el-date-picker>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="24">
      <el-col :span="24">
        <el-form-item label="登记备注">
          <el-input v-model="jobRegisterForm.bz0000" type="text" placeholder="请输入" clearable />
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button size="small" type="primary" @click="submit" :loading="loading">发 布</el-button>
    <el-button size="small" @click="handleClose">关 闭</el-button>
  </div>
</el-dialog>
</template>

<script>
import {jobRegisterApi} from "@/api/index.js"
import {commonApi} from "@/api/index.js"

export default {
  name: "job-register",
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      jobRegisterForm: {
        djlx00: '',
        djrq00: '',
        bz0000: ''
      },
      djlx00Options: [

      ],
      rules: {
        djlx00: [
          { required: true, message: '请选择登记类型', trigger: 'change' },
        ],
        djrq00: [
          { required: true, message: '请选登记日期', trigger: 'change' },
        ]
      },
      loading: false
    }
  },
  created() {

  },
  methods: {
    handleInit() {
      commonApi.queryDict('djlx00').then((res) => {
        this.djlx00Options = res.data.djlx00
      })
    },
    submit() {
      this.$refs.jobRegisterForm.validate((valid) => {
        if (valid) {
          jobRegisterApi.checkEmploymentRegister().then(res => {
            this.jobRegisterForm.sfcxdj = res.data ? '1' : '0'
            this.loading = true
            jobRegisterApi.addEmploymentRegister({...this.jobRegisterForm}).then(() => {
              this.$message.success('登记成功')
            }).finally(() => {
              this.loading = false
              this.handleClose()
            })
          })
        }
      })
    },
    handleClose() {
      this.jobRegisterForm = {
        djlx00: '',
        djrq00: '',
        bz0000: ''
      }
      this.$emit('handleClose')
    }
  }
}
</script>

<style scoped lang="scss">

</style>